<template>
  <div class="msgbox">
    <div>
      <button @click="isShow = !isShow">显示/隐藏</button>
    </div>
    <transition-group name="hello" appear>
      <span v-show="isShow" class="msg" :key="1">我是消息组件2</span>
      <span v-show="!isShow" class="msg" :key="2">我是消息组件2'</span>
    </transition-group>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isShow: true,
    };
  },
};
</script>

<style lang="less" scoped>
.msgbox {
  text-align: center;
}
.msg {
  display: block;
  margin-top: 50px;
  padding: 20px 0;
  background-color: pink;
}

.hello-enter {
  transform: translateX(-100%);
  opacity: 0;
}
.hello-enter-active {
  transition: all 0.8s linear;
}
.hello-enter-to,
.hello-leave {
  transform: translateX(0px);
  opacity: 1;
}
.hello-leave-active {
  transition: all 0.5s linear;
}
.hello-leave-to {
  transform: translateX(100%);
  opacity: 0;
}
</style>
